package alipaylogic

import (
	"context"
	"github.com/go-pay/gopay"
	"log"
	"yundian/internel/pkg/alipayex"
)

type AlipayTransferLogic struct {
	*AlipayBaseLogic
}

func NewAlipayTransferLogic() (*AlipayTransferLogic, error) {
	response := &AlipayTransferLogic{}
	var info *AlipayBaseLogic
	var err error

	if info, err = newAlipayBaseLogic(); err != nil {
		return response, err
	}

	response.AlipayBaseLogic = info
	return response, nil
}

// FundTransUniTransfer 单笔转账
func (logic *AlipayTransferLogic) FundTransUniTransfer(param *alipayex.FundTransUniTransferRequest) (
	*alipayex.FundTransUniTransferResponse, error) {
	body := make(gopay.BodyMap)
	body.Set("out_biz_no", param.OutBizNo)
	body.Set("trans_amount", param.TransAmount)
	body.Set("product_code", "TRANS_ACCOUNT_NO_PWD")
	body.Set("biz_scene", "DIRECT_TRANSFER")
	body.Set("order_title", "小电速充分红提现")

	payeeInfo := map[string]interface{}{"identity": param.OpenId, "identity_type": "ALIPAY_USER_ID"}
	body.Set("payee_info", payeeInfo)

	aliRsp, err := logic.Client.FundTransUniTransfer(context.Background(), body)
	if err != nil {
		log.Println("SystemOauthToken-err", err.Error())
	}
	return aliRsp, err
}
